package com.whfc.wxmp.api.fmam.controller;

import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.wxmp.annotation.CurrentWxUser;
import com.whfc.fuum.entity.WxUser;
import com.whfc.fvs.dto.FvsDeviceDTO;
import com.whfc.fvs.dto.FvsStreamDTO;
import com.whfc.fvs.service.FvsDeviceService;
import com.whfc.wxmp.api.fmam.service.WxFmamDeviceService;
import com.whfc.wxmp.util.RequestConetxtUtil;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 物资-设备
 *
 * @author : qzexing
 * @version : 1.0
 * @date : 2020/4/11 19:57
 */
@RestController
@RequestMapping("/mp/api/fmam/device")
public class WxFmamDeviceController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxFmamDeviceService wxFmamDeviceService;

    @DubboReference(interfaceClass = FvsDeviceService.class, version = "1.0.0")
    private FvsDeviceService fvsDeviceService;

    @GetMapping("/list")
    public Result list(@CurrentWxUser WxUser wxUser,
                       @RequestParam("deptId") Integer deptId) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                wxUser.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取设备列表", "{\"deptId\":\"" + deptId + "\"}");
        List<FvsDeviceDTO> list = wxFmamDeviceService.selectDeviceList(deptId);
        return ResultUtil.success(list);
    }

    /**
     * 获取视频监控直播地址
     *
     * @param wxUser wxUser
     * @param id     id
     * @return Result
     */
    @GetMapping(value = "/stream/url")
    public Result getStreamUrl(@CurrentWxUser WxUser wxUser,
                               @RequestParam("id") Integer id) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                wxUser.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取视频监控直播地址", "{\"id\":\"" + id + "\"}");
        FvsStreamDTO streamUrl = fvsDeviceService.getStreamUrl(id);
        return ResultUtil.success(streamUrl);
    }


}
